//import {VueSelect} from "../../static/bower_components/vue-select";
Vue.component('v-select',VueSelect.VueSelect)

let createQuestionApp = new Vue({
    el: '#createQuestionApp',
    data: {
        title: '',
        selectedTags:[],
        tags:[],
        teachers:[],
        selectedTeachers:[]
    },
    methods:{
        loadTeachers:function(){
            $.ajax({
                url: '/sys/v1/users/teacher',
                method: 'GET',
                success:function(r){
                    console.log("---------loadTeachers--------------",r);
                    if(r.code === OK){
                        let list = r.data;
                        let teachers = [];
                        for(let i=0;i<list.length;i++){
                            teachers.push(list[i].nickname);
                        }
                        createQuestionApp.teachers = teachers;
                    }
                }
            });
        },
        createQuestion:function(){
            let content = $('#summernote').val();
            let data ={
                title: this.title,
                tagNames: this.selectedTags,
                teacherNicknames: this.selectedTeachers,
                content:content
            }
            //console.log('---------create.html data---------',data);
            $.ajax({
                url: "/faq/v1/questions",
                traditional: true,   //采用传统数组编码方式，springmvc才能接收
                method: 'post',
                data: data,
                success:function(r){
                    console.log(r);
                    if(r.code === OK){
                        console.log(r.message)
                    }else {
                        console.log(r.message)
                    }
                }

            })
        },
        loadTags:function(){
            $.ajax({
                url: '/faq/v1/tags',
                method: 'GET',
                success:function(r){
                    //console.log("---------createQuestion--------------",r);
                    //if(r.code === OK){
                        let list = r.data;
                        let tags = [];
                        for(let i=0;i<list.length;i++){
                            tags.push(list[i].name);
                        }
                        createQuestionApp.tags = tags;
                    //}
                }
            });
        }
    },
    created:function(){
        this.loadTags();
        this.loadTeachers();
    }
})
